export default {
  name: 'creative',
  data () {
  	 return {
  	 	type:'img',
  	  options: [{
          value: '1',
          label: '女装'
        }, {
          value: '2',
          label: '彩妆，护肤'
        }, {
          value: '3',
          label: '女鞋'
        }, {
          value: '4',
          label: '男装'
        }, {
          value: '5',
          label: '男鞋'
        }, {
          value: '6',
          label: '箱包'
        }, {
          value: '7',
          label: '食品，茶叶，烟酒'
        }, {
          value: '8',
          label: '内衣'
        }, {
          value: '9',
          label: '保健'
        }, {
          value: '10',
          label: '饰品，服饰'
        }, {
          value: '11',
          label: '运动'
        }, {
          value: '12',
          label: '居家'
        }, {
          value: '13',
          label: '童装，母婴'
        }, {
          value: '14',
          label: '电器'
        }, {
          value: '15',
          label: '数码'
        }, {
          value: '16',
          label: '游戏'
        }, {
          value: '17',
          label: '团购'
        }, {
          value: '18',
          label: '其他'
        }],
        value:'1',
        radio:"1",
        name:'',
        click_url:'',
        is_trans_to_wifi:false
  	 }
  },
  methods:{
  	cancel(){
  		  this.$router.go(-1);
  	},
  	sure(){
  	  if(this.click_url=='' ||! /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(this.click_url))
  	  {
  	  	  this.$message.error('请输入正确格式的链接地址');
  	  	  return false;
  	  }
  	  if(!document.querySelector('#file').files || document.querySelector('#file').files.length==0)
  	  {
  	  	   this.$message.error('请上传创意图片');
  	  	   return false;
  	  }
  		let formData=new FormData();
  		formData.append('cat_id',this.value);
  		formData.append('click_url',this.click_url);
  		formData.append('is_trans_to_wifi',this.is_trans_to_wifi);
  		formData.append('image',document.querySelector('#file').files[0]);
  		formData.append('name', "上传于"+new Date().toString());
  		if(this.type=='text'){
  		 	 formData.append('name',this.name);
  		}
  		this.$http({
  		 	  method: 'post',
				  url: '/zuanzhan/creative/create',
				  data: formData,
				  headers: {
			        'Content-Type': 'multipart/form-data'
			    }
  		}).then((data)=>{
			  	if(!this.$http.interceptors(this,data))return;
			  	document.querySelector('#file').value='';
  		})
			.catch(function (error){
			    console.log(error);
			});
  	}
  }
}